package xyz.zhno.project.gateway.config;

import cn.hutool.core.collection.CollUtil;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.List;

/**
 * 网关 Swagger 配置
 * @author zh_o
 * @date 2020-11-01
 */
@Configuration
public class SwaggerConfig implements SwaggerResourcesProvider {

    @Override
    public List<SwaggerResource> get() {
        return CollUtil.newArrayList(
                getResource("service-user", "1.0.0", "/user/v2/api-docs")
        );
    }

    /**
     * 获取服务资源
     * @param name 服务名
     * @param version 版本号
     * @param url 服务 url
     * @return 服务资源信息
     */
    private SwaggerResource getResource(String name, String version, String url) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setSwaggerVersion(version);
        swaggerResource.setUrl(url);
        return swaggerResource;
    }
}
